import java.io.*;
import java.util.*;

public class BestTimeToBuyandShellStock {
    public static int maxProfit(int[] prices) {
        if(prices==null || prices.length <= 1) return 0;

        int local = 0;
        int global = 0;

        for(int i=0;i<prices.length - 1;i++){
            local = Math.max(0,local + prices[i+1] - prices[i]);
            global = Math.max(global,local);
        }

        return global;
    }
    
    public static void main(String[] args) {
        int[] stock = {1,2,3,10,5,6,7};
        System.out.println(maxProfit(stock));
    }
}